home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / Chip_2004-11_cd1.bin / zkuste / planetaria / download / celestia / celestia-win32-1.3.2.exe / {app} / shaders / texphong_nv.fp < prev   
Text File  |  2004-03-23  |  2KB  |  59 lines

  1. !!FP1.0
  2.  
  3. # Diffuse * texture + specular
  4. # Specular term is modulated by a gloss map
  5. #
  6. # Textures:
  7. # TEX0 - base texture
  8. # TEX1 - gloss map
  9. #
  10. # Interpolants:
  11. # f[TEX0] - base texture coordinates
  12. # f[TEX1] - gloss map coordinates
  13. # f[TEX2] - surface normal in object space
  14. # f[TEX3] - half angle vector in object space
  15. #
  16. # Constants:
  17. # p[0]    - object space light vector
  18. # p[2]    - diffuse color
  19. # p[3]    - specular color
  20. # p[4].x  - specular exponent
  21. # p[5]    - ambient color
  22.  
  23. MOV R0, f[TEX2]; # surface normal in R0
  24. MOV R1, f[TEX3]; # half angle vector in R1
  25.  
  26. # Normalize the surface normal (consider using a normalization cube map)
  27. DP3 R0.w, R0, R0;
  28. RSQ R0.w, R0.w;
  29. MUL R0.xyz, R0, R0.w;
  30.  
  31. # Normalize the half-angle vector
  32. DP3 R1.w, R1, R1;
  33. RSQ R1.w, R1.w;
  34. MUL R1.xyz, R1, R1.w;
  35.  
  36. # Compute the diffuse term
  37. DP3 R2.x, R0, p[0];
  38.  
  39. # Compute the specular dot product
  40. DP3 R2.y, R0, R1;
  41.  
  42. # Specular exponent in w
  43. MOV R2.w, p[4].x;
  44.  
  45. LIT R3, R2;
  46.  
  47. TEX H0, f[TEX0], TEX0, 2D;   # Sample the base texture
  48. TEX H1, f[TEX1], TEX1, 2D;   # Sample the gloss map
  49. MULX H2, R3.y, p[2];         # Diffuse color * diffuse factor
  50. ADDX_SAT H2, H2, p[5];       # Add ambient light to get 'scene color'
  51. MULX H0, H2, H0;             # Base texture * scene color
  52. MULX R3.z, R3.z, H1;         # Multiply the specular factor by the gloss map value
  53. MULX R3.z, R3.z, R3.y;       # Multiply the specular factor by the diffuse factor
  54. MADX H0, R3.z, p[3], H0;     # Multiply the specular factor by
  55.                              #   the specular color and add it in
  56. MOVX o[COLR], H0;
  57.  
  58. END
  59.